var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = cc._decorator,
    s = r.ccclass,
    c = r.property,
    p =
        (r.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.spriteTop = null;
                e.spriteDowm = null;
                e.sprIndex = 0;
                e.spfTopName = [
                    "Car_Side1",
                    "Car_TurnR1_1",
                    "Car_TurnR1_2",
                    "Car_TurnR1_3",
                    "Car_TurnR1_4",
                    "Car_TurnR1_5",
                    "Car_TurnR1_6",
                    "Car_TurnR1_7",
                    "Car_TurnR1_8",
                    "Car_TurnR1_9",
                    "Car_Top1"
                ];
                e.spfDownName = [
                    "Car_Side1c",
                    "Car_TurnR1_1c",
                    "Car_TurnR1_2c",
                    "Car_TurnR1_3c",
                    "Car_TurnR1_4c",
                    "Car_TurnR1_5c",
                    "Car_TurnR1_6c",
                    "Car_TurnR1_7c",
                    "Car_TurnR1_8c",
                    "Car_TurnR1_9c",
                    "Car_Topc"
                ];
                e.bnName = "Res";
                e.basePath = "/UI/catAnimal/cat";
                e.lastPos = cc.Vec2.ZERO;
                e.tempDir = cc.Vec2.ZERO;
                e.lastAngle = 0;
                e.time = 0;
                e.canUpdata = !1;
                e.aveAngle = 0;
                e.magDis = 10;
                return e;
            }
            e.prototype.initPos = function (t) {
                BundleManager.setSpriteAtlasCache(this.bnName, this.basePath);
                this.lastPos.x = t.x;
                this.lastPos.y = t.y;
                this.lastAngle = 0;
                this.time = 0;
                this.canUpdata = !0;
                this.aveAngle = 90 / this.spfDownName.length;
                this.setSpriteIndex(this.lastAngle);
                this.sprIndex = 0;
                this.setSpriteIndexView(0);
            };
            e.prototype.updateCurPos = function (t) {
                this.tempDir = cc.v2(t).sub(this.lastPos);
                if (this.tempDir.mag() > this.magDis) {
                    var e = Math.ceil(Math.abs(this.vector2ToAngle(this.tempDir)));
                    this.setSpriteIndex(Math.floor(e / this.aveAngle));
                    this.lastPos = cc.v2(t);
                }
            };
            e.prototype.setSpriteIndex = function (t) {
                if (this.sprIndex != t) {
                    this.sprIndex = t;
                    var e = this.sprIndex % (2 * this.spfDownName.length);
                    if (e >= this.spfDownName.length || this.sprIndex == 2 * this.spfDownName.length) {
                        e = 2 * this.spfDownName.length - e - 1;
                        this.setSpriteIndexView(e);
                        this.spriteTop.node.scaleX = -1;
                        this.spriteDowm.node.scaleX = -1;
                    } else {
                        this.spriteTop.node.scaleX = 1;
                        this.spriteDowm.node.scaleX = 1;
                        this.setSpriteIndexView(this.sprIndex);
                    }
                }
            };
            e.prototype.setSpriteIndexView = function (t) {
                if (this.spfTopName[t]) {
                    BundleManager.setSpriteAtlas(this.bnName, this.basePath, this.spfTopName[t], this.spriteTop, !1);
                    BundleManager.setSpriteAtlas(this.bnName, this.basePath, this.spfDownName[t], this.spriteDowm);
                }
            };
            e.prototype.radToAngle = function (t) {
                return (180 * t) / Math.PI;
            };
            e.prototype.vector2ToAngle = function (t) {
                return this.radToAngle((t.x > 0 ? 1 : -1) * cc.Vec3.RIGHT.angle(cc.v3(t)));
            };
            e.prototype.update = function () {
                if (this.canUpdata && Date.now() - this.time > 100) {
                    this.updateCurPos(this.node.position);
                    this.time = Date.now();
                }
            };
            n([c(cc.Sprite)], e.prototype, "spriteTop", void 0);
            n([c(cc.Sprite)], e.prototype, "spriteDowm", void 0);
            return n([s], e);
        })(cc.Component));
o.default = p;
